package com.masterrabbit.mcslf.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.masterrabbit.common.core.web.domain.AjaxResult;
import com.masterrabbit.common.core.web.page.TableDataInfo;
import com.masterrabbit.common.security.utils.SecurityUtils;
import com.masterrabbit.mcslf.contans.ResultCodeEnum;
import com.masterrabbit.mcslf.exception.McslfException;
import com.masterrabbit.mcslf.pojo.DailyFlow;
import com.masterrabbit.mcslf.pojo.vo.BusinessVo;
import com.masterrabbit.mcslf.service.DailyFlowService;
import com.masterrabbit.mcslf.utils.TimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Objects;

@RestController
@RequestMapping("/dayflow")
public class DayFlowController {
    @Autowired
    DailyFlowService dailyFlowService;
    @RequestMapping("/getinfobyate/{date}")
    public AjaxResult getInfobyDate(@PathVariable String date, HttpServletRequest request){
//        SecurityUtils.getUserId()
        HashMap<String, Object> map = new HashMap<>();
        String currentStore = request.getHeader("CurrentStore");
        if (currentStore == null || currentStore ==""){
            throw new McslfException(ResultCodeEnum.HASE_MED);
        }
        QueryWrapper<DailyFlow> objectQueryWrapper = new QueryWrapper<>();
        objectQueryWrapper.lambda().eq(DailyFlow::getMerchantId,currentStore).like(DailyFlow::getRecoedDate,date);
        DailyFlow one = dailyFlowService.getOne(objectQueryWrapper);
        if (one==null){
            return AjaxResult.success(map);
        }

//        组装饼状图数据
        LinkedList<BusinessVo> businessVos = new LinkedList<>();
        BusinessVo businessVo = new BusinessVo("保养",one.getMaintenancePrice());
        BusinessVo businessVo1 = new BusinessVo("洗车",one.getWashPrice());
        BusinessVo businessVo2 = new BusinessVo("加油",one.getRefuelingPrice());
        BusinessVo businessVo3  = new BusinessVo("维修",one.getRepairsPrice());
        businessVos.add(businessVo);
        businessVos.add(businessVo1);
        businessVos.add(businessVo2);
        businessVos.add(businessVo3);
        map.put("round",businessVos);
        LinkedList<Integer> strs = new LinkedList<>();
//        折线图
        strs.add(one.getMaNum());
        strs.add(one.getWashNum());
        strs.add(one.getRefuNum());
        strs.add(one.getRepairsNum());
        map.put("polylines",strs);
//      总收入
        map.put("PriceAmount",one.getPriceAmount());
//      总订单
        map.put("dayOrderNum",one.getDayOrderNum());
        return AjaxResult.success(map);
    }

}
